<?php
if(!isset($_SESSION['Username'])) {
	if(!isset($_SESSION)) {
		session_start();
	}
	$_SESSION['Username'] = 'guest';
	$_SESSION['logged'] = false;
}
?>
<!DOCTYPE html>
<html class="no-js" lang="en" ng-app="HelpConnect">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>HelpConnect.info - Yolanda / Haiyan</title>
  <link rel="stylesheet" href="stylesheets/hc.css">
  <link rel="stylesheet" href="stylesheets/font-awesome.min.css">
  <link rel="stylesheet" href="stylesheets/extra.css">
  <script src="javascripts/vendor/custom.modernizr.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script src="javascripts/jquery.form.min.js"></script> 
  <script src="javascripts/jquery.tablesorter.min.js"></script> 
  <script src="javascripts/angular.min.js"></script>
  <script src="javascripts/angular-ui.min.js"></script>
  <script src="javascripts/controllers.js"></script>
  <script src="javascripts/validation.js"></script>
  <script> 
  $(document).ready(function() {
    $("#donatelist").tablesorter({
      headers: {
        0:{sorter:false},
        3:{sorter:false},
        4:{sorter:false},
        6:{sorter:false}
      }
    }); 

    $(".required").change(function(event){ validateForm(); });
    $(".required").keypress(function(event){ validateForm(); });
  }); 

  function donateForm() {
    $.ajax({
      type: "POST",
      url: "functions/donate.php",
      data: $("#donateform").serialize(),
      success: function(data) { 
		window.location= './thankyou.php';
	  }
    });
  }
  
  function offerForm() {
    $.ajax({
      type: "POST",
      url: "functions/offer.php",
      data: $("#offerform").serialize(),
      success: function(data) { 
		window.location= './thankyou.php';
	  }
    });
  }
  
  function submitFlag() {
    $.ajax({
      type: "POST",
      url: "functions/flagreason.php",
      data: $("#flag_form form").serialize(),
      success: function(data) { 
		if(data == "success") { window.location= './redirect-flagged.php'; }
		else if (data == "failed") { window.location= './redirect-flagerror.php'; }
	  }
    });
  }

  function submitHelp() {
    $.ajax({
      type: "POST",
      url: "functions/help.php",
      data: $("#help_form form").serialize(),
      success: function(data) { window.location= './redirect-help.php'; }
    });
  }

  function submitDelete() {
    $.ajax({
      type: "POST",
      url: "functions/deletereason.php",
      data: $("#delete_form form").serialize(),
      success: function(data) { 
		$("html").animate({ opacity: 0, backgroundColor: '#000' }, function() {
			window.location.href= './index.php'; 
		});
	  }
    });
  }

  </script> 
  <script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "ur-b36efa59-5c29-44ad-41b-3038f20ec310", doNotHash: true, doNotCopy: true, hashAddressBar: false});</script>
</head>
<body ng-controller="HelpConnect">
  <div id="curtain" class="ng-cloak" ng-cloak ui-if="curtain">
    <div id="modals">
      <div class="modal-form">
      <article>
      <header>
        <div><h5>Entry</h5>
        </div>
        <div>Name: {{currentEntry.name}}</div>
        <div>Contact: {{currentEntry.contact}}</div>
        <div ui-if="isAdmin">Flags: {{currentEntry.flags}}</div>
        </header>
	    </article>

        <div id="flag_form" ui-if="mode == FLAG">
          <form>
			<div><p><i>Please don't leave the fields blank!</i></p></div>
            Name: <input name="name" class='required' type="text"/>
            Contact: <input name="contact" class='required' type="text"/>
            Reason: <input name="reason" class='required' type="text"/>
            <input name="donate_id" value="{{currentEntry.id}}" type="hidden"/>
			<div id="error-message-window"></div>
            <input type="submit" disabled="disabled" class="callbutton" onclick="submitFlag()" value='Flag this entry!' />
          </form>
		  <script>
			$(".required").change(function(event){ validateForm(); });
			$(".required").keypress(function(event){ validateForm(); });
		  </script>
        </div>

        <div id="delete_form" ui-if="mode == DELETE">
          <form>
            <p>Are you sure you want to delete {{currentEntry.name}}?</p>
            Reason: <input name="reason" class='required' type="text"/>
            <input name="donate_id" value="{{currentEntry.id}}" type="hidden"/>
			<div id="error-message-window"></div>
            <input type="submit" disabled="disabled" class="callbutton" onclick="submitDelete()" value='Delete this entry!' />
          </form>
		  <script>
			$(".required").change(function(event){ validateForm(); });
			$(".required").keypress(function(event){ validateForm(); });
		  </script>
        </div>

        <div id="help_form" ui-if="mode == HELP">
          <form>
            Name: <input name="name" class='required' type="text"/>
            Contact: <input name="contact" class='required' type="text"/>
            Message: <input name="details" placeholder="Hello, I would like to help out!" class='required' type="text"/>
            <input name="donate_id" value="{{currentEntry.id}}" type="hidden"/>
			<div id="error-message-window"></div>
            <input type="submit" disabled="disabled" class="callbutton" onclick="submitHelp()" value='Connect!' />
          </form>
		  <script>
			$(".required").change(function(event){ validateForm(); });
			$(".required").keypress(function(event){ validateForm(); });
		  </script>
        </div>
        
        <div id="password_form" ui-if="mode == PASSWORD">
          <form action="list-edit.php" method="post">
            <input type="hidden" name="edit_id" value="{{currentEntry.id}}"/>
            Password: <input name="Password" class='required' type="text"/>
            <input type="submit" class="callbutton" value='Edit!' />
          </form>
        </div>
        
        <a ng-click="closeModal()" class="callbutton">Close</a>
      </div>
    </div>
  </div>
  <nav>
    <div class="brand"><a href="index.php"><img src="img/negative.png" alt="HelpConnect" style="padding:0;" /></a></div>
    <div class="it"><a href="donate-form.php"><i class="fa fa-heart"></i> Donate</a></div>
    <div class="it"><a href="offer-form.php"><i class="fa fa-home"></i> Request</a></div>
    <div class="it"><a href="about.php"><i class="fa fa-group"></i> About</a></div>
    <div class="it"><a href="mailto:email@helpconnect.info"><i class="fa fa-bullhorn"></i> Contact</a></div>
  </nav>
  <h6 class="quarter"></h6>  